package com.qiuyuliantu.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qiuyuliantu.common.annotation.Log;
import com.qiuyuliantu.common.core.controller.BaseController;
import com.qiuyuliantu.common.core.domain.AjaxResult;
import com.qiuyuliantu.common.enums.BusinessType;
import com.qiuyuliantu.base.domain.QiuDiaryEntries;
import com.qiuyuliantu.base.service.IQiuDiaryEntriesService;
import com.qiuyuliantu.common.utils.poi.ExcelUtil;
import com.qiuyuliantu.common.core.page.TableDataInfo;

/**
 * 日记条目主Controller
 *
 * @author 晓君
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/base/entries")
public class QiuDiaryEntriesController extends BaseController
{
    @Autowired
    private IQiuDiaryEntriesService qiuDiaryEntriesService;

    /**
     * 查询日记条目主列表
     */
    @PreAuthorize("@ss.hasPermi('base:entries:list')")
    @GetMapping("/list")
    public TableDataInfo list(QiuDiaryEntries qiuDiaryEntries)
    {
        startPage();
        List<QiuDiaryEntries> list = qiuDiaryEntriesService.selectQiuDiaryEntriesList(qiuDiaryEntries);
        return getDataTable(list);
    }

    /**
     * 导出日记条目主列表
     */
    @PreAuthorize("@ss.hasPermi('base:entries:export')")
    @Log(title = "日记条目主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QiuDiaryEntries qiuDiaryEntries)
    {
        List<QiuDiaryEntries> list = qiuDiaryEntriesService.selectQiuDiaryEntriesList(qiuDiaryEntries);
        ExcelUtil<QiuDiaryEntries> util = new ExcelUtil<QiuDiaryEntries>(QiuDiaryEntries.class);
        util.exportExcel(response, list, "日记条目主数据");
    }

    /**
     * 获取日记条目主详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:entries:query')")
    @GetMapping(value = "/{entryId}")
    public AjaxResult getInfo(@PathVariable("entryId") Long entryId)
    {
        return success(qiuDiaryEntriesService.selectQiuDiaryEntriesByEntryId(entryId));
    }

    /**
     * 新增日记条目主
     */
    @PreAuthorize("@ss.hasPermi('base:entries:add')")
    @Log(title = "日记条目主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QiuDiaryEntries qiuDiaryEntries)
    {
        return toAjax(qiuDiaryEntriesService.insertQiuDiaryEntries(qiuDiaryEntries));
    }

    /**
     * 修改日记条目主
     */
    @PreAuthorize("@ss.hasPermi('base:entries:edit')")
    @Log(title = "日记条目主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QiuDiaryEntries qiuDiaryEntries)
    {
        return toAjax(qiuDiaryEntriesService.updateQiuDiaryEntries(qiuDiaryEntries));
    }

    /**
     * 删除日记条目主
     */
    @PreAuthorize("@ss.hasPermi('base:entries:remove')")
    @Log(title = "日记条目主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{entryIds}")
    public AjaxResult remove(@PathVariable Long[] entryIds)
    {
        return toAjax(qiuDiaryEntriesService.deleteQiuDiaryEntriesByEntryIds(entryIds));
    }
}
